package com.qf;


import com.qf.dao.ArticleDao;
import com.qf.pojo.Article;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Sort;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class test01 {
    @Autowired
    private ElasticsearchTemplate elasticsearchTemplate;
    @Autowired
    private ArticleDao articleDao;

    @Test
    public void demo01(){
        elasticsearchTemplate.createIndex(Article.class);

        elasticsearchTemplate.putMapping(Article.class);



    }

    @Test
    public void demo02(){
        List<Article> articles = new ArrayList<Article>();
        for (long i = 0; i < 100; i++) {
            Article article = new Article(i, "你的手机很好看" + i, "您的手机真的很好看" + i);
            articles.add(article);
        }
        articleDao.saveAll(articles);


    }

    @Test
    public void demo03(){
        Article article = new Article(1L, "你的手机很好看", "您的手机真的很好看");
        articleDao.save(article);

    }

    @Test
    public void demo04(){
        Article article = articleDao.findById(3l).get();
        System.out.println(article);

    }

    @Test
    public void demo05(){
        Iterable<Article> all = articleDao.findAll(Sort.by(Sort.Order.asc("id")));
        for (Article article : all) {
            System.out.println(article);
        }
    }

    @Test
    public void demo06(){
        List<Article> byTitleLikeAndIdLessThan = articleDao.findByTitleLikeAndIdLessThan("33", 50);
        byTitleLikeAndIdLessThan.stream().forEach(o-> System.out.println(o));

        for (Article article : byTitleLikeAndIdLessThan) {
            System.out.println(article);
        }





    }

}
